Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
Javascript / Why the "else" statement still work when condition is met in the "if" statement?

When try to delete the location that has dependencies to it, it throw the alert message "There's dependencie(s) to this location!" but yet still go head and ask "Are you sure to delete this record ?"

Why is this?

How can I make it alert "There's dependencie(s) to this location!" and stop there?

$('tbody').on('click', '.deleteLocationBtn', function(e){
    const selectedID = e.target.dataset.id
    let convertIDtoName;

    for (i = 0; i < arrOfLocation.length; i++) {
        if (selectedID == arrOfLocation[i].id) {
            convertIDtoName = arrOfLocation[i].name

            for (j = 0; j < arrOfDepartment.length; j++) {
                if (convertIDtoName == arrOfDepartment[j].location) {
                    alert("There's dependencie(s) to this location!")
                } else {
                    deleteLocation(selectedID)
                }
            }
        }
    }
})
const deleteLocation = (id)=> {
    event.preventDefault();         
    
        if (confirm('Are you sure to delete this record ?')) {            
            $.ajax({
                type: "GET",
                url: `companydirectory/libs/php/deleteLocationByID.php?id=${id}`,
                success: function(data) {
                    getAllLocation()
                    $("#location_data_list").load(location.href + " #location_data_list");
                },
                error:  function(request,error) {
                    console.log(request)                                   
                }
            })
        
            $("#location_data_list").load(location.href + " #location_data_list");
        }   
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda